#pragma once
#include <string>
#include <iostream>

#include "E_Calender.h"

using namespace std;

int main(int argc, char** argv){
	int intInput;
	float floatInput;
	string stringInput;

	E_Calender * calendar = new E_Calender();
	if (calendar == NULL)
		return 0;
	if (!calendar->init())
		return 0;

	while(1)  {
		cout << endl << "=======================" << endl;
		cout <<  "1. Add appointments." 	<< endl ;            
		cout <<  "2. Remove appointment" << endl ;           
		cout <<  "3. Clean Diary. "		<< endl ;         
		cout <<  "4. Find appointment "	<< endl ;  
		cout <<  "5. Copy appointment "	<< endl ;  
		cout <<  "6. Print Diary" 		<< endl ;           
		cout <<  "7. Quit." 			<< endl ;      
	
		cout <<  "Enter your choice:" << endl ; 
		int opt;

		cin >> opt;

	switch (opt)  {
		case 1:{		 //"1. Add appoiments."
			cout << "enter the day of the meeting (\"sunday=1,monday=2,...,saturday=7\") ";
			cin >> intInput;

			cout << "the meeting starts at: ";
			cin >> floatInput;
			float tmp = floatInput;

			cout << "the meeting ends at: ";
			cin >> floatInput;

			cout << "what's the meetings subject: ";
			cin >> stringInput;

			cout << "enter participants: (enter to seperate, 'end' to end input)" << endl;
			vector<string> vec;
			string name;
			for (;;){
				cin >> name;
				if (name=="end")
					break;
				vec.push_back(name);

			}

			if (!calendar->addMeeting(intInput-1, tmp, floatInput, stringInput,vec)){
				cout << "couldn't add the meeting." << endl;
			}
			break;} 			
		case 2:		//"2. Remove appoiment"
			cout << "enter the day of the meeting to remove (\"sunday=1,monday=2,...,saturday=7\") ";
			cin >> intInput;

			cout << "the meeting starts at: ";
			cin >> floatInput;

			if (!calendar->removeMeeting(intInput-1,floatInput)){
				cout << "couldn't find the meeting." << endl;
			}
			break; 			
		case 3:
			calendar->cleanCalender();
			break;
		case 4:{
			cout << "enter the day of the meeting (\"sunday=1,monday=2,...,saturday=7\") ";
			cin >> intInput;

			cout << "the meeting starts at: ";
			cin >> floatInput;

			const Meeting * m = calendar->getMeetingByStartTime(intInput-1,floatInput);
			if (m==NULL){
				cout << "no such meeting" << endl;
				break;
			} else {
				cout << "meeting subject:"<< m->getSubject() << endl;
			}


			break;}
		case 5:{ // copy
			cout << "enter the day of the meeting you want to copy (\"sunday=1,monday=2,...,saturday=7\") ";
			cin >> intInput;

			cout << "the meeting you want to copy starts at: ";
			cin >> floatInput;

			const Meeting * m = calendar->getMeetingByStartTime(intInput-1,floatInput);
			if (m==NULL){
				cout << "no such meeting" << endl;
				break;
			} else {
				cout << "enter the target day of the meeting (\"sunday=1,monday=2,...,saturday=7\") ";
				cin >> intInput;

				cout << "the target meeting starts at: ";
				cin >> floatInput;


				if (!calendar->copyMeeting(*m,intInput-1,floatInput))
					cout << "can't copy meeting" << endl;
			}

			break;}

		case 6:{
			calendar->writeToStream(cout);
			break;}
		case 7:
			delete(calendar);
			return 0;
			break;
	}		
}

	return 0;
}